package virtualdisk;

import java.io.FileNotFoundException;
import java.io.IOException;

import common.Constants.DiskOperationType;

import dblockcache.DBuffer;

public class Disk extends VirtualDisk {

	public Disk(String volName, boolean format) throws FileNotFoundException, IOException {
		super(volName, format);
	}

	@Override
	public void startRequest(DBuffer buf, DiskOperationType operation)
			throws IllegalArgumentException, IOException {
		if (operation.equals("READ")) {
			//read to buffer from volume
			buf.waitValid();
			int e = readBlock(buf);
			if (e < 0) {
				throw new IOException();
			}
			buf.setClean(true);
		}
		else if (operation.equals("WRITE")) {
			// write buffer to volume
			writeBlock(buf);
			// mark buffer as being valid
			buf.ioComplete();
		}
		else {
			throw new IllegalArgumentException();
		}
		
	}

}
